//
//  CDProducts.m
//  freeLance
//
//  Created by s.zalozniy on 4/13/13.
//  Copyright (c) 2013 Mozi Development. All rights reserved.
//

#import "CDProducts.h"
#import "CDCollections.h"
#import "CDImages.h"


@implementation CDProducts

@dynamic collection_id;
@dynamic description_;
@dynamic ident;
@dynamic isSynchronized;
@dynamic name;
@dynamic price;
@dynamic url;
@dynamic collection;
@dynamic images;

#pragma mark - Allocators

+(CDProducts *) productWithProductInfo:(Products *)productInfo inContext:(NSManagedObjectContext *)context {
    CDProducts *newProduct = [NSEntityDescription insertNewObjectForEntityForName:[[CDProducts class] description]
                                                       inManagedObjectContext:context];
    [newProduct updateWithProductInfo:productInfo inContext:context];
    
    return newProduct;
}


#pragma mark - Interface methods

-(void) updateWithProductInfo:(Products *)productInfo inContext:(NSManagedObjectContext *)context {
    self.ident = productInfo.ident;
    self.collection_id = productInfo.collection_id;
    self.name = productInfo.name;
    self.description_ = productInfo.description_;
    self.price = [NSDecimalNumber decimalNumberWithString:productInfo.price];
    self.url = productInfo.url;
    self.isSynchronized = [NSNumber numberWithBool:YES];
}

@end
